<?php

use app\assets\AppAsset;
use app\helpers\AppHelper;
use app\models\Book;
use app\models\Meta;
use app\models\Setting;
use app\models\UserFavorite;
use app\models\UserHistory;
use app\widgets\AppMenuWidget;
use app\widgets\BaseMenuWidget;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\web\View;
use yii\widgets\Breadcrumbs;
use yii\widgets\Menu;

AppAsset::register($this);

/* @var $content */
/* @var $this View */

$web_name = Setting::get('web_name');
$page_title = trim(Html::encode($this->title));
$title = Yii::$app->controller->id == Yii::$app->defaultRoute ? $web_name : "{$page_title} - {$web_name}";
$logo = Yii::$app->controller->action->id === 'item' ? 'logo2' : 'logo';
?>
<?php $this->beginPage(); ?>
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
<meta charset="<?= Yii::$app->charset; ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<?= Html::csrfMetaTags() ?>
<link rel="shortcut icon" type="image/png" href="<?= Yii::getAlias('@theme/images/icon.png'); ?>">
<?= Setting::get('web_header'); ?>
<title><?= $title; ?></title>
<?php $this->head(); ?>
<!--[if lte IE 10]>
<meta http-equiv="refresh" content="0; url='<?= Url::to(['/ie']); ?>'" />
<![endif]-->
</head>
<body class="<?= Yii::$app->controller->action->id === 'item' ? 'dark' : ''; ?>">
<?php $this->beginBody(); ?>
<div class="header">
    <div class="container grid-xl">
        <div class="navbar">
            <div class="navbar-section">
                <a class="navbar-brand mr-2" href="<?= Url::to(['/']); ?>"><img src="<?= Yii::getAlias("@theme/images/{$logo}.png"); ?>" alt="<?= Setting::get('web_name') ;?>"></a>
            </div>
            <div class="navbar-section">
                <?= Yii::$app->controller->action->id !== 'item' ? AppMenuWidget::widget() : Breadcrumbs::widget([
                    'links' => $this->params['breadcrumbs'],
                    'itemTemplate' => "<li class=\"breadcrumb-item\">{link}</li>\n"
                ]); ?>
            </div>
            <div class="navbar-section">
                <?= $this->render('header_right'); ?>
            </div>
        </div>
    </div>
</div>

<?php if(Yii::$app->controller->getRoute() === 'site/index'): ?>
    <?= $this->render('banner'); ?>
<?php endif; ?>

<div class="main" id="main">
    <div class="container grid-xl">
        <?= $content; ?>
    </div>
</div>

<?= $this->render(Yii::$app->controller->action->id !== 'item' ? 'footer' : 'item_footer', compact('web_name')); ?>

<div class="d-none"><?= Setting::get('statistics_code'); ?></div>

<?php $this->endBody(); ?>
</body>
</html>
<?php $this->endPage(); ?>
